package com.ntf.games.framework;
//-
//- Vector3f.java
//-
import java.lang.Math;

//-
//- @author Me
//-
//- 
//-
public class Vector3f
{
  // //////////////////////
  // - Member Data
  public float x, y, z;

  // //////////////////////
  // - Member Functions
  public Vector3f( float _x, float _y, float _z)
  {
    this.x = _x;
    this.y = _y;
    this.z = _z;
  }
  // //////////////////////
  // -
  public Vector3f( Vector3f _vec)
  {
    this.x = _vec.x;
    this.y = _vec.y;
    this.z = _vec.z;
  }

  // //////////////////////
  // -
  public Vector3f()
  {
    this.x = 0.0f;
    this.y = 0.0f;
    this.z = 0.0f;
  }

  // //////////////////////
  // -
  void Scale( float _scale)
  {
    this.x *= _scale;
    this.y *= _scale;
    this.z *= _scale;
  }

  // //////////////////////
  // Normalize a vector
  // Scale a vector to unit length. Easy, just scale the vector by it's length
  // inline void m3dNormalizeVector3(M3DVector3f u)
  // { m3dScaleVector3(u, 1.0f / m3dGetVectorLength3(u)); }
  void Normalize()
  {
    this.Scale( 1.0f / GetVectorLength( this));
  }

  // //////////////////////
  // Get Square of a vectors length
  // Only for three component vectors
  float GetVectorLengthSquared( Vector3f u)
  {
    return (u.x * u.x) + (u.y * u.y) + (u.z * u.z);
  }

  // //////////////////////
  // Get lenght of vector
  // Only for three component vectors.
  float GetVectorLength( Vector3f u)
  {
    return((float ) Math.sqrt( (double ) GetVectorLengthSquared( u)));
  }
  
  // //////////////////////
  // Cross Product
  // u x v = result
  // 2 component vectors only.
  public static Vector3f crossProduct( Vector3f u, Vector3f v)
  { // 0=x, 1=y, 2=z
    Vector3f result = new Vector3f();
    result.x = u.y * v.z - v.y * u.z;
    result.y = -u.x * v.z + v.x * u.z;
    result.z = u.x * v.y - v.x * u.y;

    return(result);
  }

}
